/*
 * Copyright (c) 2016 太阳花互动科技. All Rights Reserved.
 */
package com.yhyvr.api.service.store;

import com.google.common.collect.Lists;
import com.lz.mybatis.jdbc.auto.dao.BoAppBannerMapper;
import com.lz.mybatis.jdbc.auto.model.BoAppBanner;
import com.lz.mybatis.jdbc.auto.model.BoAppBannerExample;
import com.yhyvr.pojo.req.api.ApiReqData;
import com.yhyvr.pojo.req.api.banner.ApiBannerReq;
import com.yhyvr.pojo.resp.api.ApiRespData;
import com.yhyvr.pojo.resp.api.banner.BannerResp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 
* @ClassName: BannerService 
* @Description: banner轮播
* @author zhangqin
* @date 2016年4月29日 下午3:14:41 
*
 */
@Service
public class BannerService {

	@Resource
	private BoAppBannerMapper boAppBannerMapper;

	public ApiRespData<List<BannerResp>> list(ApiReqData<ApiBannerReq> apiReqData){
			List<BannerResp> bannerResps = Lists.newArrayList();
			BoAppBannerExample commonBannerQuery = new BoAppBannerExample();
		ApiBannerReq bannerReq = apiReqData.getBody();
		if(bannerReq!=null){
			commonBannerQuery.createCriteria().andStatusEqualTo(1).andTypeEqualTo(bannerReq.getType());
		}else{
			commonBannerQuery.createCriteria().andStatusEqualTo(1).andTypeEqualTo("banner");
		}
		commonBannerQuery.setOrderByClause("sort asc");
			List<BoAppBanner> commonBanners = boAppBannerMapper.selectByExample(commonBannerQuery);
			if(commonBanners!=null){
				for (BoAppBanner commonBanner : commonBanners) {
					BannerResp bannerResp = new BannerResp();
					bannerResp.setBannerImage(commonBanner.getBannerImg());
					bannerResp.setTarget(commonBanner.getTarget());
					bannerResp.setTargetType(String.valueOf(commonBanner.getTargetType()));
					bannerResp.setTitle(commonBanner.getTitle());
					bannerResp.setType(String.valueOf(commonBanner.getType()));
					bannerResps.add(bannerResp);
				}
			}
			return ApiRespData.buildSucc(bannerResps);
	}
}
